/*
 * 此页面主要是注意form 这个变量是根据contractsView.jsp页面来的
 * */
Ext.define('App.crm.billingRecordsList', {
    extend      : 'Ext.panel.Panel',
    alias       : 'widget.billingRecordsList',
    layout:'fit',
    autoScroll:true,
    autoHeight:true,
    initComponent : function() {
    	var grid,  searchFlds;
    		searchFlds = new Ext.util.MixedCollection();
    		
        var	toolbar = new Ext.Toolbar({
            enableOverflow : true,
            items : [ {
                text : "新增",
                iconCls : 'addIcon',
                handler : function() {
                    var  billingRecordsForm = Ext.create('App.crm.billingRecordsForm');
                    billingRecordsForm.show();
                    billingRecordsForm.setTitle('新增');
                }
            }, '-', {
                text : "编辑",
                iconCls : 'editIcon',
                handler : function() {
                    var sm = Ext.getCmp('billingRecordsGrid').getSelectionModel();
                    var records = sm.getSelection();
                    if (records.length <= 0) {
                        Ext.Msg.alert('错误', "未选中记录，不能修改！");
                        return;
                    }
                    var  billingRecordsForm = Ext.create('App.crm.billingRecordsForm');
                    billingRecordsForm.show();
                    billingRecordsForm.setTitle('编辑');
                    var data = records[0].data;
                    billingRecordsForm.down('form').getForm().loadRecord(records[0]);

                }
            }, '-', {
                text : "删除",
                iconCls : 'deleteIcon',
                handler : function() {
                    Ext.getCmp('billingRecordsGrid').deleteRecord();
                }
            }, "->",  , {
                text: "搜索",
                iconCls : 'searchIcon',
                handler: function () {
                    grid.load();
                }
            } ]
        });
        grid =	Ext.create('gridView',{
            remoteSort : true,
            forceFit: true,
            gridId :  'billingRecordsGrid',
            checkboxSelectionModel:true,
            searchFlds : searchFlds,
            entityClassName : 'com.rover.crm.entity.BillingRecords',
            queryUrl : 'billingRecordsController/query.action',
            deleteUrl : 'billingRecordsController/delete.action',
            recordPk : [ "id" ],
            tbar:toolbar
        });
        //如果from存在，这个变量是根据contractsView.jsp中打开的
        if(form)
        {
            grid.getStore().on('beforeload', function(store, options) {
                store.proxy.extraParams.contractsId = form.getForm().findField("id").getValue();
            }, this, true);
        }
        Ext.apply(this, {items:[grid]});
        this.callParent(arguments);
    } , destroy: function () {
        Ext.getCmp('billingRecordsList').destroy();
       this.destroy();
    }
});